<template>
  <el-form ref="detailForm" :inline="false" class="elForm" :class="isEdit?'':'formItem'">
    <!--基础信息-->
    <el-card class="box-card" shadow="never">
      <div slot="header" class="header-card" style="display: flex;justify-content: space-between;align-items: center">
        <span class="header-card-title">基础信息</span>
        <div>
          <el-button type="primary" @click="handleBatchExportTable">批量下载表格</el-button>
          <el-button type="primary" @click="handleBatchExportUpToStandard">批量下载合格证</el-button>
          <!--          <el-button type="primary">批量下载发票</el-button>-->
        </div>
      </div>

      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="车辆总台数:" prop="rentNum">
            <span> {{ detailForm.carCount }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="[1,null,''].includes(detailForm.carCount)">
          <el-form-item label="车架号:" prop="vinNo">
            <span>{{ detailForm.vinNo }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="车辆产权:" prop="propertyRightName">
            <span>{{ detailForm.propertyRightName }}</span>
          </el-form-item>
        </el-col>

      </el-row>

      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="合同禀议号:" prop="contractReportNumber">
            <span>{{ detailForm.contractReportNumber }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="采购禀议号:" prop="procurementReportNumber">
            <span>{{ detailForm.procurementReportNumber }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="合同禀议内单车保险总金额:">
            <span>{{ detailForm.totalSumAmount }}</span>
          </el-form-item>
        </el-col>
      </el-row>


      <el-row :gutter="24">
        <el-col :span="8" >
          <el-form-item label="车型:">
            <span>{{ detailForm.modelName }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="指导价:" prop="guidancePrice">
            <span>{{ format_thousand(detailForm.guidancePrice) }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="采购价:" prop="purchasePrice">
            <span>{{ format_thousand(detailForm.purchasePrice )}}</span>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="合计费用:">
            <span>{{ format_thousand(detailForm.totalPrice) }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="车船税合计费用:">
            <span>{{ format_thousand(carTax) }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="交强险合计费用:">
            <span>{{ format_thousand(jqxAmount) }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="商业险合计费用:">
            <span>{{ format_thousand(syxAmount) }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="其他保险合计费用:">
            <span>{{ format_thousand(otherInsuranceSumAmount) }}</span>
          </el-form-item>
        </el-col>
      </el-row>

    </el-card>
  </el-form>
</template>

<script>


export default {
  name: "hojiOfferInfo", //保司报价审批 基础信息

  props: {
    value: {
      type: Object,
      default: () => {
        return {};
      },
    },
    isDownload: {
      type: Boolean,
      default: false
    },
    state: {
      type: String,
      default: "",
    },
  },

  computed: {
    detailForm: {
      get() {
        let that = this
        const proxy = new Proxy(that.value, {
          get(target, key, value) {
            return Reflect.get(target, key)
          }
        })
        return proxy
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    }
  },

  watch: {
    'value.insuranceVoList': {
      handler(val) {
        if (val) {
          this.handleTotalPrice()
        }
      },
      immediate: true,
      deep: true
    },
  },

  data() {
    return {
      carTaxStatus: [],
      ids: [],
      carTax: 0,
      jqxAmount: 0,
      syxAmount: 0,
      otherInsuranceSumAmount: 0,
    };
  },

  created() {
    if (typeof this.$route.query.carId === "object") {
      this.ids = this.$route.query.carId
    } else {
      this.ids.push(this.$route.query.carId)
    }
    if (this.value.workIdList && this.value?.workIdList.length > 0) {
      this.ids = this.value?.workIdList || []
    }
    this.handleTotalPrice()
  },

  methods: {
    handleBatchExportTable() {
      this.download_json(
          "car/insurance/exportFromCarList",
          [...this.ids],
          `批量下载表格_${new Date().getTime()}.xlsx`
      )
    },
    handleBatchExportUpToStandard() {
      if (this.value.qualifiedCardOssList && this.value.qualifiedCardOssList.length > 0) {
        this.value.qualifiedCardOssList.map(a => {
          this.$download.oss(a)
        })
      }
    },
    handleTotalPrice() {
      this.carTax = 0
      this.jqxAmount = 0
      this.syxAmount = 0
      this.otherInsuranceSumAmount = 0


      for (let i = 0; i < this.value.insuranceVoList.length; i++) {
        this.carTax += Number(this.value.insuranceVoList[i].carTax)
        this.jqxAmount += Number(this.value.insuranceVoList[i].jqxAmount)
        this.syxAmount +=
            Number(this.value.insuranceVoList[i].szxPrice) +
            Number(this.value.insuranceVoList[i].ckPrice) +
            Number(this.value.insuranceVoList[i].jsyPrice) +
            Number(this.value.insuranceVoList[i].csxPrice) +
            Number(this.value.insuranceVoList[i].clPrice) +
            Number(this.value.insuranceVoList[i].hhxPrice) +
            Number(this.value.insuranceVoList[i].qtPrice) +
            Number(this.value.insuranceVoList[i].zzfwPrice)


        this.otherInsuranceSumAmount += Number(this.value.insuranceVoList[i].otherInsuranceSumAmount)
      }
      let num = Number(this.jqxAmount) + Number(this.carTax)
          + Number(this.syxAmount) + Number(this.otherInsuranceSumAmount)
      this.value.totalPrice = num
    }
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/formScss.scss";

.elForm {
  .el-form-item {
    width: 100%;
  }
}
</style>
